<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" name="" id="" placeholder="请输入年份" class="y1" />
    <input type="text" name="" id="" placeholder="请输入月份" class="m1" />
    <input type="text" name="" id="" placeholder="请输入日期" class="d1" />
    <button>点击查询</button>
  </body>
</html>
<script>
  var year = document.querySelector(".y1");
  var month = document.querySelector(".m1");
  var day = document.querySelector(".d1");
  var btn = document.querySelector("button");
  var Aday = 0;
  btn.onclick = function () {
    if (year.value.trim() == "") return alert("请输入内容");
    if (month.value.trim() == "") return alert("请输入内容");
    if (day.value.trim() == "") return alert("请输入内容");
    if (isNaN(year.value)) return alert("请输入数字");
    if (isNaN(month.value)) return alert("请输入数字");
    if (isNaN(day.value)) return alert("请输入数字");
    switch (month.value * 1 - 1) {
      case 12:
        Aday += 31;
      case 11:
        Aday += 30;
      case 10:
        Aday += 31;
      case 9:
        Aday += 30;
      case 8:
        Aday += 31;
      case 7:
        Aday += 31;
      case 6:
        Aday += 30;
      case 5:
        Aday += 31;
      case 4:
        Aday += 30;
      case 3:
        Aday += 31;
      case 2:
        if (
          year.value % 400 == 0 ||
          (year.value % 4 == 0 && year.value % 100 != 0)
        ) {
          Aday += 28;
        } else {
          Aday += 29;
        }
      case 1:
        Aday += 31;
      default:
        break;
    }
    alert("本年的第" + (Aday + day.value * 1) + "天");
  };
</script>
